package top.yqingyu.trans$client.cs.command.impl;

import top.yqingyu.qymsg.Dict;
import top.yqingyu.qymsg.MsgHelper;
import top.yqingyu.qymsg.QyMsg;
import top.yqingyu.qymsg.bean.StringKey;
import top.yqingyu.trans$client.api.Connection;
import top.yqingyu.trans$client.cs.command.Command;
import top.yqingyu.trans$client.main.TransClient;


/**
 * @author YYJ
 * @version 1.0.0
 * @ClassName top.yqingyu.transclient.cs.command.impl.Key
 * @description
 * @createTime 2023年01月10日 00:56:00
 */
public class Key extends Command {

    private static final String commandRegx = "key (get|add|rm) key:.*( val:.*)?";

    @Override
    public void deal(QyMsg msg, TransClient client) throws Exception {
        String s = MsgHelper.gainMsg(msg);
        msg.putMsg("key");

        String[] split = s.split(" ");
        String dealType = split[1];
        StringKey key = null;
        switch (dealType) {
            case "add" -> key = StringKey.add(split[2].split(":")[1], split[3].split(":")[1]);

            case "get" -> key = StringKey.get(split[2].split(":")[1]);

            case "rm" -> key = StringKey.rm(split[2].split(":")[1]);
        }
        msg.putMsgData(Dict.KEY_CMD, key);
    }

    @Override
    public void dealCommand(TransClient client, Connection conn, QyMsg msg) throws Exception {
        super.dealWrite(client, conn, msg);
    }
}